import os
import pprint
from collections import OrderedDict

from django import http
from django.core.paginator import Paginator, EmptyPage
from django.http import HttpResponse, HttpResponseNotFound
# from django.shortcuts import render
from django.shortcuts import render
from django.views import View

#
from apps.goods.models import GoodsImage, Goods, GoodsCateogory
from apps.index.utlis import get_category

from utils import constants


class IndexView(View):
#     '''商城首页'''
#
    def get(self, request):
        # 获取商品分类
        category_dict = get_category()

        # 轮播图图片获取
        lunbo = {}
        # 获取轮播图的图片
        lunbo_images = GoodsImage.objects.filter(goods_id=96)
        # print(lunbo_images)
        for lunbo_image in lunbo_images:
            lunbo['key'] = lunbo_image.image
        # pprint()
        context = {
            "categories": category_dict,
            "lunbo_images": lunbo
        }
        return render(request, 'Index.html', context)
#
# class Sculpture(View):
#     '''雕塑手办'''
#
#     def get(self, request, page_num):
#         # 雕塑手办页面图片获取
#         sculpture = {}
#         # 获取轮播图的图片
#         sculpture_images = Goods.objects.filter(id__lt=96).order_by()
#         # print(sculpture_images)
#         for sculpture_image in sculpture_images:
#             sculpture[sculpture_image.id] = {}
#             sculpture[sculpture_image.id]['name'] = sculpture_image.name
#             sculpture[sculpture_image.id]['image'] = sculpture_image.front_image
#             sculpture[sculpture_image.id]['current_price'] = sculpture_image.current_price
#             # print(sculpture[sculpture_image.id])
#         # 创建分页器
#         paginator = Paginator(sculpture_images, constants.GOODS_LIST_LIMIT)
#         # 获取每页商品的数据
#         try:
#             page_skus = paginator.page(page_num)
#         except EmptyPage:
#             return http.HttpResponseNotFound('empty page')
#         # 获取列表页总页数
#         total_page = paginator.num_pages
#         # print(sculpture)
#         # for item in sculpture:
#         #     print(sculpture[item]["name"])
#         context = {
#             'sculpture': sculpture,
#             'sculpture_images': sculpture_images,
#             'page_skus': page_skus,  # 分页后每页数据
#             'total_page': total_page,  # 总页数
#             'page_num': page_num  # 当前页码
#         }
#         return render(request, 'Sculpture.html', context)
# #
# #
# class PlushDolls(View):
#     '''毛绒玩偶'''
#
#     def get(self, request):
#         # 毛绒玩偶页面图片获取
#         stuffed = {}
#         # 获取毛绒玩偶的图片
#         stuffed_images = Goods.objects.filter(id__gt=96, id__lte=140)
#         # print(sculpture_images)
#         for stuffed_image in stuffed_images:
#             stuffed[stuffed_image.id] = {}
#             stuffed[stuffed_image.id]['name'] = stuffed_image.name
#             stuffed[stuffed_image.id]['image'] = stuffed_image.front_image
#             stuffed[stuffed_image.id]['current_price'] = stuffed_image.current_price
#         print(stuffed)
#         for item in stuffed:
#             print(stuffed[item]["name"])
#         context = {
#             'stuffed': stuffed,
#             'stuffed_images': stuffed_images,
#         }
#         return render(request, 'PlushDolls.html', context)
#
#
# class Costume(View):
#     '''男女服饰'''
#
#     def get(self, request):
#         # 男女服饰页面图片获取
#         costume = {}
#         # 获取男女服饰的图片
#         costume_images = Goods.objects.filter(id__gt=140, id__lte=280)
#         # print(sculpture_images)
#         for costume_image in costume_images:
#             costume[costume_image.id] = {}
#             costume[costume_image.id]['name'] = costume_image.name
#             costume[costume_image.id]['image'] = costume_image.front_image
#             costume[costume_image.id]['current_price'] = costume_image.current_price
#         print(costume)
#         for item in costume:
#             print(costume[item]["name"])
#         context = {
#             'costume': costume,
#             'costume_images': costume_images,
#         }
#         return render(request, 'Costume.html', context)
#
#
# class Surrounding(View):
#     '''赛事周边'''
#
#     def get(self, request):
#         # 赛事周边页面图片获取
#         surrounding = {}
#         # 获取赛事周边的图片
#         surrounding_images = Goods.objects.filter(id__gt=285, id__lte=315)
#         # print(sculpture_images)
#         for surrounding_image in surrounding_images:
#             surrounding[surrounding_image.id] = {}
#             surrounding[surrounding_image.id]['name'] = surrounding_image.name
#             surrounding[surrounding_image.id]['image'] = surrounding_image.front_image
#             surrounding[surrounding_image.id]['current_price'] = surrounding_image.current_price
#         print(surrounding)
#         for item in surrounding:
#             print(surrounding[item]["name"])
#         context = {
#             'surrounding': surrounding,
#             'surrounding_images': surrounding_images,
#         }
#         return render(request, 'Surrounding.html', context)
#
#
# class Jewelry(View):
#     '''珠宝首饰'''
#
#     def get(self, request):
#         # 珠宝首饰页面图片获取
#         jewelry = {}
#         # 获取珠宝首饰的图片
#         jewelry_images = Goods.objects.filter(id__gt=315, id__lte=331)
#         # print(sculpture_images)
#         for jewelry_image in jewelry_images:
#             jewelry[jewelry_image.id] = {}
#             jewelry[jewelry_image.id]['name'] = jewelry_image.name
#             jewelry[jewelry_image.id]['image'] = jewelry_image.front_image
#             jewelry[jewelry_image.id]['current_price'] = jewelry_image.current_price
#         print(jewelry)
#         for item in jewelry:
#             print(jewelry[item]["name"])
#         context = {
#             'jewelry': jewelry,
#             'jewelry_images': jewelry_images,
#         }
#         return render(request, 'Jewelry.html', context)
#
#
# class Else(View):
#     '''其他'''
#
#     def get(self, request):
#         # 其他页面图片获取
#         Else = {}
#         # 获取其他页面的图片
#         Else_images = Goods.objects.filter(id__gt=331, id__lte=369)
#         # print(sculpture_images)
#         for Else_image in Else_images:
#             Else[Else_image.id] = {}
#             Else[Else_image.id]['name'] = Else_image.name
#             Else[Else_image.id]['image'] = Else_image.front_image
#             Else[Else_image.id]['current_price'] = Else_image.current_price
#         print(Else)
#         for item in Else:
#             print(Else[item]["name"])
#         context = {
#             'Else': Else,
#             'Else_images': Else_images,
#         }
#         return render(request, 'Else.html', context)
